def BellmanFord(edges_value, N, start):
    min_dist = [float('inf')] * (N+1)
    min_dist[start] = 0
    
    for i in range(1, N):
        
        update = False
        for s, t, val in edges_value:
            if min_dist[s] != float('inf') and min_dist[s]+val < min_dist[t]:
                min_dist[t] = min_dist[s]+val
                update = True
        
        if not update:
            break
    return min_dist
        
            
def main():
    N, M = map(int, input().split())
    edges_value = []
    for i in range(M):
        edges_value.append(list(map(int, input().split())))
    
    min_dist = BellmanFord(edges_value, N, 1)
    if min_dist[-1] == float('inf'):
        print("unconnected")
    else:
        print(min_dist[-1])
    
main()